# LDFLAGS = -lpthread  # 添加链接库
# ./MyProject/bin/MyProject:./MyProject/src/*.c  ./MyProject/include/*.h 
# 	gcc -o $@ $^


# 项目配置
PROJECT_NAME = MyProject
BUILD_DIR = ./$(PROJECT_NAME)/bin
SRC_DIR = ./$(PROJECT_NAME)/src
INCLUDE_DIR = ./$(PROJECT_NAME)/include
OBJ_DIR = ./$(PROJECT_NAME)/obj

# 编译器和编译选项
CC = gcc
CFLAGS = -Wall -Wextra -O2 -I$(INCLUDE_DIR)
# 添加需要的链接库
LDFLAGS = -lsqlite3 -lwebsockets -ljson-c -lcrypto
DEBUG_FLAGS = -g -DDEBUG

# 源文件和目标文件
SRC = $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/*.h)
OBJ = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))

# 目标可执行文件
TARGET = $(BUILD_DIR)/$(PROJECT_NAME)

# 默认目标
all: $(TARGET)

# 创建必要的目录
$(shell mkdir -p $(BUILD_DIR) $(OBJ_DIR))

# 链接规则
$(TARGET): $(OBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

# 编译规则
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
	$(CC) $(CFLAGS) -c $< -o $@

# # 调试版本
# debug: CFLAGS += $(DEBUG_FLAGS)
# debug: $(TARGET)

# 清理规则
clean:
	rm -rf $(OBJ_DIR) $(TARGET)

# # 运行规则
# run: $(TARGET)
# 	$(TARGET)

# 伪目标声明
.PHONY: all clean debug run